home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Lib / =Using ListControl.c < prev    next >
Encoding:
Text File  |  1992-10-22  |  9.0 KB  |  190 lines  |  [TEXT/MPS ]

  1. ***** ListControl.c usage documentation *****/
  2.  
  3. Purpose:  To simplify List handling within a window.
  4.  
  5. Implementing a List control does the following:
  6.  
  7. 1) Makes using lists in a non-dialog window easier.
  8. 2) The List is automatically associated with the window, since
  9.    it is in the window's control list.
  10. 4) Updating of the List is much simpler, since all that is
  11.    necessary is to draw the control (or all the window's controls with
  12.    a DrawControls call).
  13. 5) What isn't handled automatically by tracking the control can be handled
  14.    with a direct call.  There are simple calls to handle List events.
  15. 6) When you close the window, the ListRecord is disposed of.
  16.    (This automatic disposal can easily be defeated.)
  17.  
  18.  
  19.  
  20. To create a List control, you only need a single call.  For example:
  21.  
  22.     list = CLNew(rViewCtl,            /* Resource ID of view control for List control. */
  23.                  &viewRect,            /* View rect of list.                             */
  24.                  numRows,            /* Number of rows to create List with.             */
  25.                  numCols,            /* Number of columns to create List with.         */
  26.                  cellHeight,
  27.                  cellWidth,
  28.                  theLProc,            /* Custom List procedure resource ID.             */
  29.                  window,            /* Window to hold List control.                     */
  30.                  clHScroll | blBrdr | clActive);    /* Horizontal scrollbar, active List. */
  31.     
  32. The various choices for the List control are defined as follows:
  33.  
  34. #define clHScroll        2
  35. #define clVScroll        8
  36. #define clActive        32
  37. #define clShowActive    64
  38. #define clKeyPos        128
  39. #define clTwoStep        256
  40. #define clDrawIt        0x8000
  41.  
  42. clHScroll:            Create a list that includes a horizontal scrollbar.
  43. clVScroll:            Create a list that includes a vertical scrollbar.
  44. clActive:            Make this the initially active control for the window.
  45. clShowActive:        When the control is active, show that it is by drawing a selection
  46.                     border around the control.  This is the new 7.0 human-interface
  47.                     method of showing which control is active.
  48. clKeyPos:            Allow list positioning, based on user keypresses.  This assumes that
  49.                     the list is alphabetized so that key presses for location make sense.
  50.                     If typing by the user is fast enough, multiple characters will be
  51.                     used for the positioning.
  52. clTwoStep:            When using IsCtlEvent(), you may want the initial click on a List
  53.                     control to just select the control, or you may wish the click to start
  54.                     tracking in addition to selecting the control.  The tracking is
  55.                     considered the second step.  By setting this bit, you indicate that you
  56.                     want control selection and item selection to be a 2-step process.
  57.                     Setting this bit means that it will take 2 separate clicks by the
  58.                     user to select an item in the list if the list is inactive.
  59. clDrawIt:            This is a List manager flag that is needed for the LNew() call.
  60.  
  61.  
  62. If the CLNew call succeeds, you then have a List control in your
  63. window.  It will be automatically disposed of when you close the window.
  64. If you don't want this to happen, then you can detach it from the
  65. view control which owns it.  To do this, you would to the following:
  66.  
  67.     viewCtl = CLViewFromList(theListHndl);
  68.     if (viewCtl) SetCRefCon(viewCtl, nil);
  69.  
  70. The view control keeps a reference to the List record in the refCon.
  71. If the refCon is cleared, then the view control does nothing.  So, all that
  72. is needed to detach a List record from a view control is to set the
  73. view control's refCon nil.  Now if you close the window, you will still
  74. have the List record.
  75.  
  76.  
  77. To remove a List control completely from a window, just dispose of the view
  78. control that holds the List record.  To do this, just do something like the below:
  79.  
  80.     DisposeControl(CLViewFromList(theListHndl));
  81.  
  82. This completely disposes of the List control.
  83.  
  84.  
  85. Events for the List record are handled nearly automatically.  Just make the
  86. following call:
  87.  
  88.     CLEvent(eventPtr, &action);
  89.  
  90. If the event was handled, true is returned.  If the event is false, then the
  91. event doesn't belong to a List control, and further processing of the event
  92. should be done.
  93.  
  94.  
  95.  
  96. Here is a list of the functions and a description as to their purpose:
  97.  
  98. void            CLActivate(Boolean active, ListHandle listHndl);
  99.     /* Activate this List record.  Activation is not done by calling LActivate().
  100.     ** The active control is indicated by the 2-pixel thick border around the
  101.     ** List control.  This allows all List controls in a window to display which
  102.     ** cells are selected.  This behavior can be overridden by calling LActivate()
  103.     ** on the List record for List controls.
  104.     ** Human interface dictates that only at most a single List control has this
  105.     ** active border.  For this reason, this function scans for other List
  106.     ** controls in the window and removes the border from any other that it finds. */
  107.  
  108. Boolean            CLClick(EventRecord *event, short *action);
  109.     /* This is called when a mouseDown occurs in the content of a window.  It
  110.     ** returns true if the mouseDown caused a List action to occur.  Events
  111.     ** that are handled include if the user clicks on a scrollbar that is
  112.     ** associated with a List control. */
  113.  
  114. ControlHandle    CLCtlHit(void);
  115.     /* The List control that was hit by calling FindControl is saved in a
  116.     ** global variable, since the CDEF has no way of returning what kind it was.
  117.     ** To determine that it was a List control that was hit, first call this
  118.     ** function.  The first call returns the old value in the global variable,
  119.     ** plus it resets the global to nil.  Then call FindControl(), and then
  120.     ** call this function again.  If it returns nil, then a List control
  121.     ** wasn't hit.  If it returns non-nil, then it was a List control that
  122.     ** was hit, and specifically the one returned. */
  123.  
  124. Boolean            CLEvent(EventRecord *event, short *action);
  125.     /* Handle the event if it applies to the active List control.  If some
  126.     ** action occured due to the event, return true. */
  127.  
  128. ListHandle        CLFindActive(WindowPtr window);
  129.     /* Returns the active List control, if any.  If nil is passed in, then
  130.     ** the return value represents whatever List control is active, independent
  131.     ** of what window it is in.  If a window is passed in, then it returns a
  132.     ** List control only if the active control is in the specified window.
  133.     ** If the active List control is in some other window, then nil is returned. */
  134.  
  135. Boolean            CLFindCtl(WindowPtr window, EventRecord *event, ListHandle *listHndl, ControlHandle *ctlHit);
  136.     /* This determines if a List control was clicked on directly.  This does
  137.     ** not determine if a related scrollbar was clicked on.  If a List
  138.     ** control was clicked on, then true is returned, as well as the List
  139.     ** handle and the handle to the view control. */
  140.  
  141. ListHandle        CLFromScroll(ControlHandle scrollCtl, ControlHandle *retCtl);
  142.     /* Find the List record that is related to the indicated scrollbar. */
  143.  
  144. short            CLInsert(ListHandle listHndl, char *data, short dataLen, short row, short col);
  145.     /* Insert a cell alphabetically into the list.  Whichever parameter is passed in
  146.     ** as -1, either row or column, that is the dimension that is determined. */
  147.  
  148. Boolean            CLKey(EventRecord *event);
  149.     /* See if the keypress event applies to the List control, and if it does,
  150.     ** handle it and return true. */
  151.  
  152. ListHandle        CLNew(short viewID, Rect *vRect, short numRows, short numCols, short cellHeight, short cellWidth, short theLProc, WindowPtr window, short mode);
  153.     /* Create a new List control.  See the comments at the beginning of this
  154.     ** file for more information. */
  155.  
  156. ControlHandle    CLNext(WindowPtr window, ListHandle *listHndl, ControlHandle ctl);
  157.     /* Get the next List control in the window.  You pass it a control handle
  158.     ** for the view control, or nil to start at the beginning of the window.
  159.     ** It returns both a List handle and the view control handle for that
  160.     ** List record.  If none is found, nil is returned.  This allows you to
  161.     ** repeatedly call this function and walk through all the List controls
  162.     ** in a window. */
  163.  
  164. void            CLPrint(RgnHandle clipRgn, ListHandle listHndl, short *row, short *col, short leftEdge, Rect *drawRct);
  165.     /* From the starting for or column, print as many cells as will fit into the
  166.     ** designated rect.  Pass in a starting row and column, and they will be
  167.     ** adjusted to indicate the first cell that didn't fit into the rect.  If all
  168.     ** remaining cells were printed, the row is returned as -1.  The bottom of the
  169.     ** rect to print in is also adjusted to indicate where the actual cut-off
  170.     ** point was. */
  171.  
  172. short            CLRowOrColSearch(ListHandle listHndl, char *data, short dataLen, short row, short col);
  173.     /* Find the location in the list where the data would belong if inserted.  The row
  174.     ** and column are passed in.  If either is -1, that is the dimension that will be
  175.     ** determined and returned. */
  176.  
  177. void            CLUpdate(RgnHandle clipRgn, ListHandle list);
  178.     /* Draw the List control in the correct form. */
  179.  
  180. ControlHandle    CLViewFromList(ListHandle listHndl);
  181.     /* Return the control handle for the view control that owns the List
  182.     ** record.  Use this to find the view to do customizations such as changing
  183.     ** the update procedure for this List control. */
  184.  
  185. void            CLWindActivate(WindowPtr window);
  186.     /* This window is becoming active or inactive.  The borders of the List
  187.     ** controls need to be redrawn due to this.  For each List control in the
  188.     ** window, redraw the active border. */
  189.  
  190.